<template>
  <div class="admin-type-edit">
    <el-form :model="form" ref="form" label-width="80px" v-loading="loading" :rules="rules">
      <el-form-item label="分类名称" prop="typeName">
        <el-input v-model="form.typeName" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="分类描述" prop="remark">
        <el-input v-model="form.remark" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="排序权重" prop="rank">
        <el-input v-model.number="form.rank" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label>
        <el-button type="primary" @click="edit('form')">提交</el-button>
        <el-button type="reset" @click="resetForm('form')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "admin-type-edit",
  props: ["closeDialog", "id", "updateSuccess"],
  data: function() {
    return {
      form: {
        typeName: "",
        remark: "",
        rank:0
      },
      loading: false,
      rules: {
        typeName: { required: true, message: "分类名称不能为空!" }
      }
    };
  },
  mounted: function() {
    this.getType1();
  },
  methods: {
    //添加一级分类
    edit: function(form) {
      this.loading = true;
      this.$refs[form].validate().then(() => {
        this.axios.post("videoType/updateType1", this.form).then(res => {
          this.updateSuccess();
          if (res.data.success) {
            this.$message({
              message: "修改成功!",
              type: "success",
              duration: 1000,
              onClose: () => {
                this.closeDialog();
                this.loading = false;
              }
            });
            //this.resetForm('form');
          }
        });
      });
    },
    //重置按钮
    resetForm: function(form) {
      this.$refs[form].resetFields();
    },
    getType1() {
      this.loading = true;
      this.axios.post("videoType/getType1ById", { id: this.id }).then(res => {
        this.form = res.data.type1;
        this.loading = false;
      });
    }
  },
  watch: {
    id: function() {
      this.getType1();
    }
  }
};
</script>

<style scoped>
</style>